"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var TransformInterceptor_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransformInterceptor = void 0;
// src/interceptor/transform.interceptor.ts
const common_1 = require("@nestjs/common");
const operators_1 = require("rxjs/operators");
const log4js_1 = require("../../utils/log4js");
let TransformInterceptor = TransformInterceptor_1 = class TransformInterceptor {
    intercept(context, next) {
        const req = context.getArgByIndex(1).req;
        console.log('拦截器', req.url);
        if (req.url.startsWith('/nest-vue-short-passage') ||
            req.url.startsWith('/nest-status') ||
            TransformInterceptor_1.whiteList.includes(req.url)) {
            return next.handle();
        }
        return next.handle().pipe((0, operators_1.map)((data) => {
            const logFormat = ` <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        Request original url: ${req.originalUrl}
        Method: ${req.method}
        IP: ${req.ip}
        User: ${JSON.stringify(req.user)}
        Response data:\n ${JSON.stringify(data)}
        <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<`;
            log4js_1.Logger.access(logFormat);
            log4js_1.Logger.log(logFormat);
            console.log('全局响应拦截器方法返回内容后...');
            return {
                code: 200,
                timestamp: new Date().toISOString(),
                path: req.url,
                message: '成功',
                data: data,
            };
        }));
    }
};
exports.TransformInterceptor = TransformInterceptor;
TransformInterceptor.whiteList = ['/', '/uploads', '/static', 'nest-web']; //白名单
exports.TransformInterceptor = TransformInterceptor = TransformInterceptor_1 = __decorate([
    (0, common_1.Injectable)()
], TransformInterceptor);
